package cn.wolfcode.cloud.shop.util;

import cn.wolfcode.cloud.shop.common.CodeMsg;
import cn.wolfcode.cloud.shop.common.Result;
import lombok.*;
import org.springframework.beans.factory.annotation.Autowired;
import sun.applet.Main;

import javax.validation.constraints.NotNull;
import java.text.MessageFormat;

/**
 * @Description: 会员登入异常信息封装实体类
 * @Author: 伍家钰
 * @Date: 2020/9/6 13:21
 * @Version: 1.0
 */
@Getter
@Setter
@NoArgsConstructor
public class MemberCodeMsg extends CodeMsg {
    public static final MemberCodeMsg LOGIN_ERROR = new MemberCodeMsg(50101, "账号或密码不能为空");
    public static final MemberCodeMsg USERNAME_NO_EXIST = new MemberCodeMsg(50102, "账号不存在");
    public static final MemberCodeMsg PASSWORD_ERROR = new MemberCodeMsg(50103, "密码不正确");
    public static final MemberCodeMsg PARAM_ERROR = new MemberCodeMsg(50104, "参数异常信息:{0}");

    public MemberCodeMsg(int code, String msg) {
        super(code, msg);
    }

    // 覆盖Message的format方法,
    public MemberCodeMsg format(String... args) {
        MemberCodeMsg mcm = new MemberCodeMsg();
        mcm.setCode(this.getCode());
        mcm.setMsg(MessageFormat.format(this.getMsg(), args));
        return mcm;
    }


    //================== 奇葩bugger测试,结果正常 ====================
    /*public static MemberCodeMsg aaa(String msg){
        MemberCodeMsg mm = MemberCodeMsg.PARAM_ERROR;
        mm.setMsg(MessageFormat.format(mm.getMsg(), msg));
        return mm;
    }

    public static void main(String[] args) {
        MemberCodeMsg ssss = aaa("哈哈哈哈");
        System.out.println(ssss.getMsg());
        System.out.println("======================");
        MemberCodeMsg hhhh = aaa("呵呵呵呵");
        System.out.println(hhhh.getMsg());
    }*/

    //================== 演示占位符{0}的效果 ====================
   /* public static void main(String[] args) {
        String str = "你好呀:{0},{1}";
        String q = MessageFormat.format(str,"小明","小红");
        System.out.println(q);
    }*/

}
